﻿using SoundEngine3.DspPlugins;
using ZquenceStudio3.Core;
using ZquenceStudio3.DspPlugins;
using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine;
using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine.Modules.HighLevel;
using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine.Waveforms;
using ZquenceStudio3.Core.Storage;
using System;

namespace ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer
{
    public class ModulizerDescription : IDspPlugin
    {
        public DspPluginInfo GetDspPluginInfo()
        {
            return new DspPluginInfo("Modulizer", DspType.Synthesizer);
        }

        public BaseDspPluginInstance CreateDsp(ZquenceStudio3Context context, DspPluginInfo info)
        {
            return new Modulizer(context, info);
        }
    }

    [Obsolete]
    public class NodesizerDescription : IDspPlugin
    {
        public DspPluginInfo GetDspPluginInfo()
        {
            return new DspPluginInfo("Nodesizer", DspType.Synthesizer, true);
        }

        public BaseDspPluginInstance CreateDsp(ZquenceStudio3Context context, DspPluginInfo info)
        {
            return new Modulizer(context, info);
        }
    }

    public class Modulizer : BaseModulizer
    {
        public Modulizer(ZquenceStudio3Context coreContext, DspPluginInfo dspPlugin)
            : base(coreContext, dspPlugin, ModuleManager.ModulizerType.Synthesizer)
        {
        }

        protected override void CreateDefaultBuilder()
        {
            OscilatorModule osc = new OscilatorModule(mModuleManager);
            mModuleManager.AddSubModule(osc);

            BasicWaveformsModule waveforms = new BasicWaveformsModule(mModuleManager);
            mModuleManager.AddSubModule(waveforms);

            osc.InPitch.FromOutput = mModuleManager.MidiInput.MidiOut;
            osc.InRunAndIdle.FromOutput = mModuleManager.MidiInput.MidiOut;
            osc.InWaveform.FromOutput = waveforms.OutWaveform;

            mModuleManager.Out.Left.FromOutput = osc.Output;
            mModuleManager.Out.Right.FromOutput = osc.Output;

            mModuleManager.MidiInput.GuiPosition.X = 100;
            mModuleManager.MidiInput.GuiPosition.Y = 5;
            mModuleManager.MidiInput.GuiPosition.Width = 100;
            mModuleManager.MidiInput.GuiPosition.Height = 1;

            osc.GuiPosition.X = 200 + 100;
            osc.GuiPosition.Y = 5;
            osc.GuiPosition.Width = 100;
            osc.GuiPosition.Height = 1;

            waveforms.GuiPosition.X = 100;
            waveforms.GuiPosition.Y = 6.3;
            waveforms.GuiPosition.Width = 100;
            waveforms.GuiPosition.Height = 1;

            mModuleManager.Out.GuiPosition.X = 300 + 200;
            mModuleManager.Out.GuiPosition.Y = 5;
            mModuleManager.Out.GuiPosition.Width = 100;
            mModuleManager.Out.GuiPosition.Height = 1;
        }
        
        protected override void OnUnpacked()
        {

        }
    }
}
